package com.zjeav.lingjiao.base.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dalimao.corelibrary.utils.ConvertUtils;
import com.zjeav.lingjiao.R;
import com.zjeav.lingjiao.base.baseBean.LocalMetadata;
import com.zjeav.lingjiao.base.utils.StringUtils;

public class DownloadBookAdapter extends BaseQuickAdapter<LocalMetadata, BaseViewHolder> {
    private Context context;
    private int mType = 0;

    public DownloadBookAdapter(Context context) {
        super(R.layout.downloadbook_item);
        this.context = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, LocalMetadata item) {

        String strtltle  ="";
        String strtimelenght  ="";
        String strfilesize  ="";
        String strloadtime  ="";
        if (StringUtils.isNullOrEmpty(item.getTitle())){
            strtltle = "";
        }else {
            strtltle = item.getTitle();
        }

        if (StringUtils.isNullOrEmpty(String.valueOf(item.getDuration()))){
            strtimelenght = "";
        }else {

            long a=item.getDuration();
            long b=60;
            strtimelenght = (a/b)+":"+(a%b);
        }

        if (StringUtils.isNullOrEmpty(item.getFilesize())){
            strfilesize = "";
        }else {
            strfilesize = item.getFilesize();
        }

        if (StringUtils.isNullOrEmpty(item.getFavoritesTime())){
            strloadtime = "";
        }else {
            strloadtime = item.getFavoritesTime();
        }

        helper.setText(R.id.name, strtltle);
        helper.setText(R.id.timelenght, strtimelenght);
        helper.setText(R.id.filesize, strfilesize);
        helper.setText(R.id.downloadtime, strloadtime);
        helper.setText(R.id.action_txt, "学习");

        ImageView imageView = helper.getView(R.id.image);
        Glide.with(context)
                .load(item.getCover())
                .into(imageView);


        helper.addOnClickListener(R.id.action_txt);

    }
}